package com.jf.car.dao.impl;

import com.jf.car.bean.CarImage;
import com.jf.car.dao.CarImageDao;
import com.jf.car.util.BaseDao;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class CarImageDaoImpl implements CarImageDao {
    @Override
    public int batchImage(List<CarImage> list) {
        StringBuilder sql = new StringBuilder("insert into car_image values");
        List<Object> objs = new ArrayList<>();
        for(CarImage img : list){
            sql.append("(null,?,?),");
            objs.add(img.getCarId());
            objs.add(img.getCarImage());
        }
        sql=new StringBuilder(sql.substring(0,sql.lastIndexOf(",")));
        return BaseDao.baseBatch(sql.toString(),list.size(),objs);
    }

    @Override
    public List<CarImage> getListByCarId(int carId) {
        String sql = "select * from car_image where car_id = ?";
        return BaseDao.baseQuery(CarImage.class,sql,carId);
    }

    @Override
    public int deleteByCarId(int carId) {
        String sql = "delete from car_image where car_id = ?";
        return BaseDao.baseUpdate(sql,carId);
    }
}
